home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group00b.txt
/
000070_icon-group-sender _Mon Oct 9 08:16:44 2000.msg
< prev
next >
Wrap
Internet Message Format
|
2001-01-03
|
3KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id IAA00555
for icon-group-addresses; Mon, 9 Oct 2000 08:14:35 -0700 (MST)
Message-Id: <200010091514.IAA00555@baskerville.CS.Arizona.EDU>
Date: Sat, 7 Oct 2000 08:16:35 -0700
From: Steve Wampler <swampler@noao.edu>
To: David Feustel <dfeustel@mindspring.com>
Cc: icon-group@optima.CS.Arizona.EDU
Subject: Re: Suspend Question
Content-Disposition: inline
User-Agent: Mutt/1.1.9i
Errors-To: icon-group-errors@optima.CS.Arizona.EDU
Status: RO
Content-Length: 2019
On Sat, Oct 07, 2000 at 09:32:59AM -0500, David Feustel wrote:
> I haven't been able to find an answer to these 2 questions
> in any of the Icon/Unicon documentation that I have.
> Can someone enlighten me please?
>
> How is a procedure that uses suspend to return a result
> invoked so as to continue from the point of suspension?
>
> How is that procedure 'reset' so that the next value returned
> by the procedure is the first value generated?
I assume you're asking how these operations are implemented and
so "Magic" won't suffice...
Warning, the following explanation ignores the ugly details:
A suspended procedure hasn't gone away - it's stack frame and
surrounding context is still on the execution stack. If you
picture the execution stack as containing context information
then a procedure call adds an evaluation frame to some context
(e.g. x := a + f(b)
has the stack (growing to the right:
x a b
at the point of the call of f. Expressions inside f add
to this context, so the stack looks something like:
x a b X Y Z
where X Y Z are 'local' context in f. When f suspends it
hides its local context (which includes the current PC)
So if the suspend is "suspend c", the stack looks like
x a b X Y Z PC x a c
Note that the information needed to resume f is all there
on the stack, so if backtracking goes back into f, the
stack is quickly reset to
x a b X Y Z
and the PC can be reset in f to continue at the point of
suspension. If the goal of the expression evaluation is met,
then the entire context is removed from the stack, including
that part of the context that was 'hidden' by the suspend of f.
This is efficient because it turns out that the amount of
context that needs to be copied (the 'x a c' above) is
typically surprisingly small, thanks to the bounded expressions
in Icon.
As to 'resetting to start over', there is nothing that needs
to be done this is just another call of the function.
--
--
Steve Wampler- SOLIS Project, National Solar Observatory
swampler@noao.edu